package com.leyou.page.controller;

import com.leyou.page.service.FileService;
import com.leyou.page.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("item")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private FileService fileService;

    /**
     * 跳转商品详情页
     */
    @GetMapping("{id}.html")
    public String toItemPage(Model model, @PathVariable("id") Long id) {
        //调用方法,获取静态页面需要的动态数据
        Map<String, Object> modelMap = this.goodsService.loadModel(id);
        model.addAllAttributes(modelMap);//把数据封装到model域中,相当于存在了request中;
        // 判断是否需要生成新的页面
        if(!this.fileService.exists(id)){
           // this.fileService.syncCreateHtml(id);
        }
        return "item";
    }

}
